<template>
<div :class="$style.container">
  <h4>
    <p>
      <i :class="$style.icon"/>
      <span>{{title}}</span>
    </p>
    <router-link tag="em" :to="{path:'/more'}">更多</router-link>
  </h4>
  <swiper :options="swiperOption">
    <swiper-slide v-for="(item,idx) in lists" :key="'action'+idx" :class="$style.item">
      <div @click.stop="handleItemClick(item)">
        <img v-lazy="item.poster">
        <div>
          <h3 :class="$style.title">{{item.original_title}}</h3>
          <div :class="$style.desc">
            <div :class="$style.price">
              <span v-if="item.price" :class="$style.f1"><small>￥</small><strong>{{item.price}}</strong></span>
              <span v-else :class="$style.f2">免费</span>
            </div>
            <p v-if="item.price" :class="$style.btn">
              <x-button mini v-if="item.price && !item.isMyFilm">购买</x-button>
              <x-button mini v-else-if="item.price && item.isMyFilm">已购买</x-button>
            </p>
          </div>
        </div>
      </div>
    </swiper-slide>
  </swiper>
</div>
</template>

<script>
import { swiper, swiperSlide } from 'vue-awesome-swiper'
export default {
  props: {
    lists: {
      type: Array,
      default: () => []
    },
    title: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      swiperOption: {
        slidesPerView: 2.2,
        spaceBetween: 50
      }
    }
  },
  components: {
    swiper,
    swiperSlide
  },
  methods: {
    handleItemClick (item) {
      this.$emit('handleItem', item)
    }
  }
}
</script>

<style lang='less' module>
.container {
  padding: 20px 20px 0px;
  box-sizing: border-box;
  h4 {
    line-height: 0;
    margin-bottom: 10px;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    .icon {
      display: inline-block;
      width: 18px;
      height:18px;
      background: url('../../../assets/imgs/index_icon.png') no-repeat;
      background-position-x: center;
      background-size:18px;
      background-position: 0px -18px;
      vertical-align: middle;
    }
    span {
      margin-left:10px;
      font-size:14px;
      font-weight: bold;
      color:#2b333b;
      vertical-align: middle;
    }
    em {
      font-size:14px;
      color:#2b333b;
      vertical-align: middle;
    }
  }
  .item {
    img {
      width: 150px;
      height:100px;
      object-fit: cover;
      border-radius: 3px;
      border: 1px solid #fff;
    }
    .title {
      color: #2B333B;
      font-size: 15px;
      font-weight: bold;
      line-height: 20px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      word-break: break-all;
      word-wrap: break-word;
    }
    .desc {
      display: flex;
      flex-direction: row;
      flex-wrap: nowrap;
      justify-content: space-between;
      line-height: 0px;
      align-items: center;
      .price {
        span {
          font-size: 12px;
          line-height: 14px;  
        }
        .f1 {
          color: red;
        }
        .f2 {
          color: #be9e4d;
        }
      }
      .btn {
        button {
          background: red;
          color:#fff;
        }
      }
    }
  }
}

</style>
<style>
@import 'swiper/dist/css/swiper.css';
</style>